package com.example.ymm.modules1.service.impl.hl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.hl.yw.YwMoneyChangeLog;
import com.example.ymm.modules1.mapper.hl.YwMoneyChangeLogMapper;
import com.example.ymm.modules1.query.hl.YwMoneyChangeLogQueryCriteria;
import com.example.ymm.modules1.service.hl.YwMoneyChangeLogService;
import com.example.ymm.util.QueryHelpPlus;
import com.example.ymm.util.UtilValidate;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
//@Transactional
@Slf4j
@DS("slave2")
public class YwMoneyChangeLogServiceImpl extends BaseServiceImpl<YwMoneyChangeLogMapper, YwMoneyChangeLog> implements YwMoneyChangeLogService {

    @Override
    public TableList<YwMoneyChangeLog> list(YwMoneyChangeLogQueryCriteria criteria, YmPageDto pageDto) {
        getPage(pageDto);
        List<YwMoneyChangeLog> arrs = queryAll(criteria);
        PageInfo<YwMoneyChangeLog> pageInfo = new PageInfo<>(arrs);
        TableList<YwMoneyChangeLog> tableList = new TableList(pageInfo);
        return tableList;
    }

    public List<YwMoneyChangeLog> queryAll(YwMoneyChangeLogQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(YwMoneyChangeLog.class, criteria);
        predicate.orderByAsc("create_time");
        List<YwMoneyChangeLog> result =baseMapper.selectList(predicate);
        return result;
    }


    @Override
    public YwMoneyChangeLog getByOrderNo(String orderNo) {
        YwMoneyChangeLogQueryCriteria criteria=new YwMoneyChangeLogQueryCriteria();
        criteria.setOrderNo(orderNo);
        List<YwMoneyChangeLog> changeLogs = queryAll(criteria);
        if(UtilValidate.isNotEmpty(changeLogs)){
            return changeLogs.get(0);
        }
        return null;
    }
}
